from django.conf.urls import url, include
from django.contrib import admin
from django.views import static
from django.conf import settings

from content.views import post_detail, edit_post, collection_status, post_action
from bbs.views import posts_list, sign_status, sign, update_avatar, upload_file, search
from user.views import login_view, logout_view, register, \
    home, setting, user_posts, messages, repass, add_comment, comment_action, find_user

urlpatterns = [
    url(r'^manageadmin/docs/', include('django.contrib.admindocs.urls')),
    url(r'^manageadmin/', admin.site.urls),
    # 存在安全风险，后续需要删除
    url(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
    url(r'^media/(?P<path>.*)$', static.serve, {'document_root': settings.MEDIA_ROOT}),

    url(r'^$', posts_list, name="index"),
    url(r'^catalog/(?P<catalog_id>\d+)/$', posts_list, name="catalog"),
    url(r'^search/$', search, name="search"),

    # Post
    url(r'^post/(?P<post_id>\d+)/$', post_detail, name="post_detail"),
    url(r'^post/add/$', edit_post, name="add_post"),
    url(r'^post/(?P<post_id>\d+)/edit/$', edit_post, name="edit_post"),
    url(r'^post/(?P<post_id>\d+)/action/$', post_action, name="post_action"),
    url(r'^collection/find/(?P<post_id>\d+)/', collection_status),

    # User
    url(r'^user/login/$', login_view, name="login"),
    url(r'^user/logout/$', logout_view, name="logout"),
    url(r'^user/register/$', register, name="register"),
    url(r'^user/home/$', home, name="user_home"),
    url(r'^user/(?P<user_id>\d+)/$', home, name="user_home_other"),
    url(r'^user/setting/$', setting, name="user_setting"),
    url(r'^user/posts/$', user_posts, name="user_posts"),
    url(r'^user/messages/$', messages, name="user_messages"),
    url(r'^user/repass/$', repass, name="user_repass"),

    # api
    url(r'^api/sign/status/$', sign_status),
    url(r'^api/sign/$', sign),
    url(r'^api/avatar/update/$', update_avatar),
    url(r'^api/upload/$', upload_file),
    url(r'^jump/$', find_user),

    # comment
    url(r'^comment/add/$', add_comment),
    url(r'^comment/(?P<comment_id>\d+)/action/$', comment_action),
]
